<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
	.addtd{border:1px solid #f5f5f5; padding-left: 15px;}
	.addtdother{border:1px solid #f5f5f5; padding-left: 15px; border-top: none;}
</style>
</head>
<body class="easyui-layout">
<!-- 会员信息 -->
<div data-options="region:'west',split:true,title:'会员信息'" style="width:200px;padding:0px;">
	<div class="zTreeDemoBackground left" style="width:100%">
		<ul id="memTree" class="ztree"></ul>
	</div>
</div>
<!-- 会员详细信息 -->
<div data-options="region:'center',fit:true" class="easyui-layout">
	<div data-options="region:'north',border:true,title:'添加会员'" style="height:155px;">
		<input type="hidden" id="form_pid" value="" />
		<form id="form_add" method="post" class="easyui-form" data-options="novalidate:true">
			<input type="hidden" name="pid" id="form_pidw" value="" />
			<input type="hidden" name="id" id="form_id" value="" />
			<table style="width:99%; margin-left: auto; margin-right: auto; line-height: 35px; font-size: 12px; background-color:#f9fdff;">
				<tr>
					<td class="addtd" style="border-left:none; text-align: left; width: 90px;">直属上级</td>
					<td class="addtd" style="border-left:none; width:120px"><span id="f_name"></span></td>
					<td class="addtd" style="text-align: left; width: 90px;">姓名</td>
					<td class="addtd" style="border-left:none; width:120px"><input id="form_name" class="easyui-textbox" style="width:100px;" data-options="required:true,prompt:'请输入姓名',missingMessage:'姓名为必填项'" type="text" name="name"></input></td>
					<td class="addtd" style="border-left:none; text-align: left; width: 90px;">银行卡号</td>
					<td class="addtd" style="border-left:none;"><input class="easyui-textbox" id="form_bank_card_id" type="text" style="width: 200px" data-options="prompt:'请输入银行卡号'" name="bank_card_id"></input></td>
				</tr>
			</table>
			<table style="width:99%; margin-left: auto; margin-right: auto; line-height: 35px; font-size: 12px; background-color:#f9fdff;">
				<tr>
					<td class="addtd" style="border-left:none; text-align: left; width: 90px;">手机号</td>
					<td class="addtd" style="border-left:none; width:120px"><input id="form_mphone" class="easyui-textbox" style="width:100px;" type="text" data-options="required:true,validType:'phoneRex',invalidMessage:'手机号格式不正确',prompt:'请输入手机号',missingMessage:'手机号为必填项'"  name="mphone"></input></td>
					<td class="addtd" style="border-left:none; text-align: left; width: 90px;">微信号</td>
					<td class="addtd" style="border-left:none; width:120px"><input id="form_weixin" class="easyui-textbox" style="width:100px;" type="text" data-options="required:true,prompt:'请输入微信号',missingMessage:'微信号为必填项'"  name="weixin"></input></td>
					<td class="addtd" style="border-left:none; width:120px;padding-left: 30px;" colspan="2">
						<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_add" style="padding-left: 2px; padding-right: 2px" iconCls="icon-save">保  存</a>&nbsp;&nbsp;
						<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_clear" style="padding-left: 2px; padding-right: 2px" iconCls="icon-clear">取  消</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center'">
		<div id="the_panel" class="easyui-panel" data-options="fit:true,title:'发展的会员'">
			<table id="datagrid" class="easyui-datagrid" data-options="fit:true,fitColumns:true,
				pagination:true,pageSize:15,pageList:[5,10,15,20],url:'search', onClickRow:gridClick,toolbar:'#fd'">
				<thead>
					<tr>
						<th data-options="field:'ID',checkbox:true"></th>
						<th data-options="field:'M_TRUE_NAME'">姓名</th>
						<th data-options="field:'MPHONE'">手机号</th>
						<th data-options="field:'WEIXIN'">微信号</th>
						<th data-options="field:'BANK_CARD_ID'">银行卡号</th>
						<th data-options="field:'FLOWING_WATER'">打款流水号</th>
						<th data-options="field:'MESSAGE'">留言</th>
						<th data-options="field:'REG_TIME'">注册时间</th>
						<th data-options="field:'EXA_TIME'">审核时间</th>
						<th data-options="field:'CREATE_TIME'">创建时间</th>
						<th data-options="field:'ACTIVE'">状态</th>
						<th data-options="field:'URL'">推广地址</th>
					</tr>
				</thead>
			</table>
		</div>
		<div id="fd">
			<a href="javascript:void(0)" id="btn_sk" class="easyui-linkbutton" iconCls="icon-edit">审核</a>
		</div>
	</div>
</div>
</body>
</html>
<@h.easyui />
<@h.zTree />
<script type="text/javascript">
//点击表格事件
function gridClick(index, row){
	jQuery("#form_add").form("load",{
		name:row.M_TRUE_NAME,
		card_id:row.CARD_ID,
		id:row.ID,
		mphone:row.MPHONE,
		weixin:row.WEIXIN,
		bank_card_id:row.BANK_CARD_ID
	});
}
//设置面板名字
function setPanelTitle(value){
	jQuery("#the_panel").panel("setTitle",value+"发展的会员");
}
//初始化树
function initTree(){
	var setting = {
		data: {
			simpleData:{
				idKey:"ID",
				pIdKey:"PID",
				rootPid:null,
				enable: true
			},
			key:{
				name:"M_TRUE_NAME"
			}
		},
		async: {
			enable: true,
			type:"post",
			url:"leftSearch"
		},
		callback:{onClick:zTreeOnClick}
	};
	jQuery.fn.zTree.init(jQuery("#memTree"), setting);
}
jQuery(document).ready(function(){
	initTree();
	//审核事件
	jQuery("#btn_sk").click(function(){
		var rows = jQuery("#datagrid").datagrid("getChecked");
		if(rows.length<1){
			jQuery.messager.alert("系统提示","请先择一条需审核的会员信息","info");
			return;
		}
		var hefa=true;
		var ids="";
		//循环判断
		jQuery.each(rows,function(index, row){
			if(row.ACTIVE=="已审核"){
				hefa=false;
			}
			ids=ids+row.ID+",";
		});
		if(!hefa){
			jQuery.messager.alert("系统提示","您选中的会员信息存在已审核状态","info");
			return;
		}
		jQuery.ajax({
			async:false,
			type:"post",
			dataType:"json",
			data:{ids:ids},
			url:"shuser",
			success:function(info){
				if(!info.success){
					jQuery.messager.alert("系统提示",info.message,"warning");
					return;
				}
				gridate();
				initTree();
			}
		});
	});
	//添加事件
	jQuery("#btn_add").click(function(){
		if(jQuery("#form_pid").val()==""){
			jQuery.messager.alert("系统提示","请先选择一个会员作为上级会员","info");
			return;
		}
		jQuery("#form_pidw").val(jQuery("#form_pid").val());
		
		if(!jQuery("#form_add").form("enableValidation").form("validate")){
			return;
		}
		//jQuery.messager.alert("系统提示","验证成功","info");
		//return;
		jQuery("#form_add").form("submit",{
			success:function(data){
				var obj = eval('(' + data + ')');
				if(obj.success){
					gridate();
					initTree();
					jQuery("#form_add").form("clear");
					jQuery("#form_add").form("disableValidation");
				}else{
					jQuery.messager.alert("系统提示",obj.message,"info");
				}
			},
			url:"dosave"
		});
	});
	jQuery("#btn_clear").click(function(){
		jQuery("#form_add").form("clear");
		jQuery("#form_add").form("disableValidation");
	});
});
//重新加载表格
function gridate(){
	jQuery("#datagrid").datagrid("reload",{
		pid:jQuery("#form_pid").val()
	});
}
//双击树事件
function zTreeOnClick(event, treeId, treeNode, clickFlag){
	treeNode.click = "return false;"
	var tmp_name = treeNode.M_TRUE_NAME;
	setPanelTitle(tmp_name);
	jQuery("#f_name").empty();
	jQuery("#f_name").append(tmp_name);
	jQuery("#form_pid").val(treeNode.ID);
	gridate();
	return false;
}
</script>